
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>显示学生信息</title>
</head>
<script type="text/javascript" src="/js/jquery-1.8.3.js"></script>
<body>
<div>
    <a href="/admin/addStudent.jsp">增加学生点这里</a>
    <form action="/GetStudentByKeyServlet">
    选择查看学生信息 院系：
    <select name="yid">
        <option value="0">请选择院系</option>
        <option value="1">1中文系</option>
        <option value="2">2数学系</option>
        <option value="3">3信息工程</option>
        <option value="4">4土木工程</option>
    </select>
    专业：
    <select name="zid">
        <option value="0">请选择专业</option>
        <option value="1">1文言文专业</option>
        <option value="2">2文学历史专业</option>
        <option value="3">3基础数学专业</option>
        <option value="4">4应用数学</option>
    </select>
    班级：
    <select name="cid">
        <option value="0">请选择班级</option>
        <option value="1">1班</option>
        <option value="2">2班</option>
        <option value="3">3班</option>
    </select>
        年级：
        <select name="gid">
            <option value="0">请选择年级</option>
            <option value="2016">2016</option>
            <option value="2017">2017</option>
            <option value="2018">2018</option>
        </select>
        <input type="submit" value="搜索" id="sou">
    </form>
</div>

    <table border="1px solid" cellspacing="0" cellpadding="0" width="80%" id="ta">
        <tr>
            <td colspan="7" style="color: green;font-size: 40px" align="center">学生列表</td>
        </tr>
        <tr>
            <th>学生编号</th>
            <th>学生姓名</th>
            <th>学生班级</th>
            <th>学生专业</th>
            <th>学生院系</th>
            <th>学生年级</th>
            <th>操作</th>
        </tr>
    </table>
<table>
    <tr>
        <td align="center">
            <a href="javascript:;" id="first" class="page">首页</a>
            <a href="javascript:;" id="prev" class="page">上一页</a>
            <a href="javascript:;" id="next" class="page">下一页</a>
            <a href="javascript:;" id="last" class="page">尾页</a>
        </td>
    </tr>
</table>


<script>
    var currPage;
    var pages;
    $(function(){
        var getStudent=function (curr) {
            $.ajax({
                type:'POST',
                url:"StudentPageServlet",
                dataType:'JSON',
                data:{
                    pagesize:7,
                    currpage:curr||1,
                },
                success:function (data) {
                    //先删除之前显示页的数据
                    $("#ta").find("tr[class='studentdata']").remove();
                    $.each(data.studentList,function (index,obj) {
                        var rows="<tr class='studentdata' align='center'>"+
                            "<td >"+obj.sId+"</td>"+
                            "<td>"+obj.sName+"</td>"+
                            "<td>"+obj.cid+"</td>"+
                            "<td>"+obj.yid+"</td>"+
                            "<td>"+obj.zid+"</td>"+
                            "<td>"+obj.gid+"</td>"+
                            "<td><a href=\"GetStudentServlet?sid="+obj.sId+"\">修改</a>"+
                            "<a href=\"DeleteStudentServlet?sid="+obj.sId+"\">删除</a></td>"+
                            "</tr>";
                        $("#ta").append(rows);
                    });
                    currPage=data.currPage;
                    pages=data.countPages;
                }
            });
        };

        $(".page").click(function () {
            var flag = $(this).attr("id");
            if (flag == "first") {
                getStudent(1);
            } else if (flag == "prev") {
                currPage--;
                if(currPage<1){
                    currPage=1;
                }
                getStudent(currPage);
            } else if (flag == "next") {
                currPage++;
                if(currPage>pages){
                    currPage=pages;
                }
                getStudent(currPage);
            } else if (flag == "last"){
                getStudent(pages);
            }

        });

        getStudent();

    });
</script>


</body>
</html>
